@echo off
chcp 65001 >nul
echo === API测试脚本 ===

set BASE_URL_ORDER=http://localhost:8080
set BASE_URL_INVENTORY=http://localhost:8081

REM 测试创建订单
echo 1. 测试创建订单...
curl -s -X POST %BASE_URL_ORDER%/api/orders ^
  -H "Content-Type: application/json" ^
  -d "{\"orderId\": \"ORDER_001\", \"customerId\": \"CUSTOMER_001\", \"items\": [{\"productId\": \"PRODUCT_001\", \"productName\": \"商品A\", \"quantity\": 2, \"unitPrice\": 100.0}, {\"productId\": \"PRODUCT_002\", \"productName\": \"商品B\", \"quantity\": 1, \"unitPrice\": 50.0}], \"totalAmount\": 250.0}"

echo.
echo.

REM 等待事件处理
echo 2. 等待事件处理...
timeout /t 3 /nobreak >nul

REM 查看库存状态
echo 3. 查看库存状态...
curl -s %BASE_URL_INVENTORY%/api/inventory/status

echo.
echo.

REM 测试支付订单
echo 4. 测试支付订单...
curl -s -X POST %BASE_URL_ORDER%/api/orders/ORDER_001/pay ^
  -H "Content-Type: application/json" ^
  -d "{\"paymentId\": \"PAY_001\", \"paymentMethod\": \"ALIPAY\", \"amount\": 250.0}"

echo.
echo.

REM 等待事件处理
echo 5. 等待事件处理...
timeout /t 3 /nobreak >nul

REM 再次查看库存状态
echo 6. 再次查看库存状态...
curl -s %BASE_URL_INVENTORY%/api/inventory/status

echo.
echo.

REM 测试取消订单
echo 7. 测试取消订单...
curl -s -X POST %BASE_URL_ORDER%/api/orders/ORDER_001/cancel ^
  -H "Content-Type: application/json" ^
  -d "{\"reason\": \"客户主动取消\"}"

echo.
echo.

REM 等待事件处理
echo 8. 等待事件处理...
timeout /t 3 /nobreak >nul

REM 最终查看库存状态
echo 9. 最终查看库存状态...
curl -s %BASE_URL_INVENTORY%/api/inventory/status

echo.
echo.
echo === 测试完成 ===
pause

